package org.i1510.base.utils.file;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.i1510.base.bean.FileBean;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;

public class FileManager {

	/**
	 * @Author Rambo
	 * @Desc：可使用通配符读取路径文件存到List<FileBean>
	 * @param location
	 * @return
	 * @throws IOException
	 *             TODO
	 * @Version XMLManager.java,v 1.1 2013-10-8 下午6:26:24
	 */
	public List<FileBean> readFile(String location) throws IOException {
		ResourcePatternResolver resourceLoader = new PathMatchingResourcePatternResolver();
		Resource[] source = resourceLoader.getResources(location);
		List<FileBean> fileList = new ArrayList<FileBean>();
		for (int i = 0; i < source.length; i++) {
			Resource resource = source[i];
			FileBean fileBean = new FileBean();
			fileBean.setFile(resource.getFile());
			fileBean.setFileName(resource.getFilename());
			fileBean.setFilePath(resource.getFile().getPath());
			System.out.println(resource.getFile().getPath());
			fileList.add(fileBean);
		}
		return fileList;
	}

	

	public static void main(String[] args) {
		String path = "/Users/rambo/Downloads/temp/";
		File file = new File(path);
		File[] tempList = file.listFiles();
		System.out.println("该目录下对象个数：" + tempList.length);
		for (int i = 0; i < tempList.length; i++) {
			if (tempList[i].isFile()) {
				System.out.println("文     件：" + tempList[i]);
			}
			if (tempList[i].isDirectory()) {
				System.out.println("文件夹：" + tempList[i]);
			}
		}
	}
}